package com.hldsmart.smartda.activity.assistant;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.hldsmart.smartda.R;
import com.hldsmart.smartda.adapter.ShopGoodsAdapter;
import com.hldsmart.smartda.base.BaseActivity;
import com.hldsmart.smartda.model.entity.ShopEntity;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

public class ShopGoodsActivity extends BaseActivity implements View.OnClickListener{

    @Bind(R.id.iv_shopgoods_back)
    ImageView iv_shopgoods_back;
    @Bind(R.id.rv_shopgoods_goods)
    RecyclerView rv_shopgoods_goods;

    private ShopGoodsAdapter shopgoodsAdapter;
    private LinearLayoutManager LayoutManager;
    private ArrayList<ShopEntity> shopEntities;


    public static void startShopGoodsActivity(Context context) {
        Intent intent = new Intent(context, ShopGoodsActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_goods_shop);
        ButterKnife.bind(this);
        LayoutManager=new LinearLayoutManager(this);//设置布局管理器  
        LayoutManager.setOrientation(OrientationHelper.VERTICAL);
        rv_shopgoods_goods.setLayoutManager(LayoutManager);//设置为垂直布局，这也是默认的 
        shopgoodsAdapter=new ShopGoodsAdapter();
        rv_shopgoods_goods.setAdapter(shopgoodsAdapter);
        initData();
        setListener();
    }

    private void initData(){
        shopEntities=new ArrayList<>();
        shopEntities.add(new ShopEntity("1",R.drawable.ken,"肯德基","特价优惠，全场八折起，超值全家桶，赠送可乐薯条","24.00","48","快餐/外卖"));
        shopEntities.add(new ShopEntity("2",R.drawable.xietupian,"特步女鞋","天天特价秋冬季运动鞋男鞋减震气垫跑步女鞋情侣鞋","89.00","111","女鞋/特步"));
        shopEntities.add(new ShopEntity("3",R.drawable.xin,"星巴克","情人节，特价优惠，全场八折起，第二杯半价哦","68.00","99","饮品/咖啡"));
        shopEntities.add(new ShopEntity("4",R.drawable.shopim,"班尼路服装","特价优惠，全场八折起，提供免费茶水，免费停车位","170.00","288","服装/上衣"));
        shopEntities.add(new ShopEntity("5",R.drawable.ubz,"UBZ女鞋","特价优惠特步女鞋秋冬款名牌运动鞋轻便皮面旅游休闲鞋","68.00","99","女鞋/特步"));
        shopgoodsAdapter.addData(shopEntities);
        shopgoodsAdapter.notifyDataSetChanged();
    }

    private void setListener() {
        iv_shopgoods_back.setOnClickListener(this);
        shopgoodsAdapter.setListener(new ShopGoodsAdapter.OnItemClickedListener() {
            @Override
            public void onPhotoClicked(ShopEntity shopEntity) {
                GoodsDetailActivity.startGoodsDetailActivity(ShopGoodsActivity.this);
            }
        });

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_shopgoods_back:
                finish();
                break;
        }
    }
}
